import takeOut from '../../../config/api/takeOut'
var WxNotificationCenter = require("../../../config/WxNotificationCenter");

Page({

  data: {
    activeNames: [],
    conferenceList: [{
      name: "加载中"
    }],
  },
  loadData() {
    let vm = this;
    //加载商品列表
    takeOut.commodityList({
      "pageNo": 1,
      "pageSize": 9999
    }, function (res) {
      let list = res.data.data.records;
      list
      vm.setData({
        conferenceList: list
      })
    })
  },
  clickitem(e) {
    let index = e.currentTarget.dataset.item;
    wx.redirectTo({
      url: '../conference/conference?list=' + JSON.stringify(this.data.conferenceList) + "&selectindex=" + index,
    })
  },
  onChange(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  clickadd() {
    wx.navigateTo({
      url: '../add/add',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.loadData();
    var that = this
    WxNotificationCenter.addNotification('addgoods', that.loadData, that)

  },
  clickedit(e) {
    let item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: '../add/add?item=' + JSON.stringify(item),
    })
  },
  clickdel(e) {
    let item = e.currentTarget.dataset.item;
    let content = `确定要删除${item.name}么?`
    let vm = this;
    wx.showModal({
      title: '提示',
      content: content,
      success(res) {
        if (res.confirm) {
          //开始删除
          wx.showLoading({
            title: '取消中...',
          })
          meetingRoom.meetingRoomdel({
            "id": item.id
          }, function (res) {
            wx.hideLoading({
              success: (res) => {},
            })
            if (res.data.status == 200) {
              wx.showToast({
                title: '删除成功',
                icon: "none"
              })
            } else {
              wx.showToast({
                title: res.data.msg,
                icon: "none"
              })
            }
            vm.loadData();
          })
        } else if (res.cancel) {

        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    var that = this
    WxNotificationCenter.removeNotification('addgoods', that)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})